
templateViewInit = ()=>{
    top.tools.cache.set('roleFrom','false')
    searchFormInfo();
    let parentWidth = $('#role-list').parent().parent().attr("layui-width") - 30;
    let userId = $('#role-list').parent().parent().attr("userId")
    let checkboxList = [];
    top.API.user().getRole({id:userId},(res)=>{
        checkboxList = res.data
        tableReturnFilter = function (data){
            for (let i = 0; i < data.length; i++) {
                let b =  checkboxList.some((obj) => {
                    return obj.roleId === data[i].id;
                });
                if (b){
                    data[i].LAY_CHECKED = true;
                }
            }
            return data;
        }
    })
    // 已知数据渲染
    var inst = table.render({
        elem: '#role-list',
        id:'role-list-id',
        height:472,
        width:parentWidth,
        url: top.tools.getBaseUrl()+'/role/getPage',
        method: 'post',
        headers:{
            'Access-Token':top.tools.cookie.token(),
            'Content-Type':'application/json',
        },
        cols: [
            [
                {type: 'checkbox', width: 50},
                {type: 'numbers', title: '序号', align: 'center', width: 60},
                {field: 'name', title: '角色名称', align: 'left', width: 250},
                {field: 'type', title: '菜单类型', align: 'center',width: 100,templet:function (d){
                        let type = top.tools.dict().getDictLabel('system_role_type',d.type)
                        return type;
                    }},
                {field: 'dataScope', title: '数据范围', align: 'center'},
                {field: 'status', title: '状态', align: 'center',width: 100,templet:function (d){
                        return '<input type="checkbox" name="status" id="'+d.id+'" value="'+d.status+'" ' +
                            'title="启用|停用" lay-skin="switch" disabled '+( d.status ? "checked" : "" )+'>';
                    }},
            ]
        ],
        parseData: dataToTreeFormat,
        data:[
            {id:1,name:'用户性别',type:'system_user_sex',status:'0',remark:'',createTime:'2021-01-05 17:03:48'}
        ],
        //skin: 'line', // 表格风格
        //even: true,
        page: true, // 是否显示分页
        limits: [10, 20, 30,50],
        limit: 10, // 每页默认显示的数量
        done: function (res, curr, count) {
            $(".layui-table th[data-field=" + 0 + "] .layui-table-cell").html("");
            top.tools.cache.set('roleFrom','true');
        }
    });
    // 工具栏事件
    table.on('toolbar(role-list)', function (obj) {
        var id = obj.config.id;
        var checkRow = table.checkStatus(id);
        if (checkRow.data.length<=0 && obj.event !== 'add'){
            layer.msg("请选择数据！");
            return
        }
        var data = checkRow.data;
        if (obj.event === 'add') {
            openForm({
                title:"新增角色",
                btn:1,
                save:(closeid)=>{
                    formFun.save(inst,closeid)
                },
                reset:(closeid)=>{
                    form.val('role_form', top.tools.form.getFindElementOnObj("#lay-role-form",false));
                },
                before:(index,layero,that,isEdit)=>{
                    workdbFieldConvert(document.querySelectorAll('#lay-role-form .dict-module'),isEdit);
                    form.val('role_form', {
                        sort:table.cache['role-list-id'].length+1,
                        status:true
                    });
                },
                area:'40%'
            },'role_form')
        } else if (obj.event === 'view') {
            openForm({
                title:"查看角色",
                btn:-1,
                area:'40%',
                before:(index,layero,that,isEdit)=>{
                    workdbFieldConvert(document.querySelectorAll('#lay-role-form .dict-module'),isEdit);
                    form.val('role_form', data);
                }
            },'role_form')
        } else  if (obj.event === 'del') {
            openConfirm(()=>{
                formFun.remove(data,inst)
            });
        }
    });

    queryButton('role-list-id');

}

